package com.ocean.elasticSearch.controller;

import com.ocean.elasticSearch.entity.DocBean;
import com.ocean.elasticSearch.entity.SysLogs;
import com.ocean.elasticSearch.service.LogService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;

/**
 * @version 1.0
 * @className: LogController
 * @description: TODO
 * @author: lxq
 * @date: 2021/4/15
 **/
@Log4j2
@RestController
@RequestMapping("/elastic/logs")
public class LogController {
    @Autowired
    private LogService logService;

    @GetMapping(value="index")
    public String  index() {
        return "log/index";
    }
    @GetMapping("/init")
    public void init(){
        SysLogs log = new SysLogs();
        log.setUsername("小马云");
        log.setOperation("开源中国社区");
        log.setMethod("com.itstyle.es.log.controller.index()");
        log.setIp("192.168.1.70");
        log.setExceptionDetail("开源中国社区");
        log.setParams("{'name':'码云','type':'开源'}");
        log.setDeviceType((short)1);
        log.setPlatFrom((short)1);
        log.setLogType((short)1);
        log.setDeviceType((short)1);
        log.setId((long)0);
        log.setUserId((long)1);
        log.setTime((long)1);
        logService.saveLog(log);
    }

    @GetMapping("/all")
    public Iterator<SysLogs> all(){
        return logService.findAll();
    }
    @GetMapping("/delete")
    public Iterator<SysLogs> delete(){
        return logService.findAll();
    }

    @GetMapping(value="list")
    @ResponseBody
    public Page<SysLogs> list() {
        return logService.searchLogPage(1, 20, 1, "");
    }
}
